Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proper symlink handling for layers and projects #60140

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

vsydorov
Copy link

@vsydorov vsydorov commented Jan 14, 2025

Description

This PR addresses #60135 and #19524 issues involving the incorrect handling of symlinks in QGIS when saving projects. There are two main contributions:

  • Prevent QGIS from silently resolving symlinks on save.
    In qgspathresolver.cpp, two calls to QFileInfo::canonicalFilePath() are replaced with QDir::cleanPath(fi.absoluteFilePath()). When saving layer datasources, QGIS this preserves relative paths without inadvertently resolving symlinks.
  • Follow symlinks when saving the "%_attachments.zip" component of a .qgs project.
    QGIS deletes and recreates the .zip on each project save, removing the symlink if one exists. This PR ensures the symlink’s target is deleted and recreated instead, aligning with expected behavior when editing a symlinked file.

Several tests cover various symlink scenarios::

  • testSymlinks1LayerRasterChange. Verifies correct expected behavior when a raster layer’s symlink target changes, as described in the dynamic data updates usecase from #60135 and #19524.
  • testSymlinks2LayerFolder. Checks that a symlinked data folder maintains correct relative paths, consistent with the multi-machine synchronization workflow from #60135.
  • testSymlinks3LayerShapefile. Tests that individually symlinked shapefile components maintain relative paths, allowing workflows like git-annex.
  • testSymlinks4LayerShapefileBroken. Confirms consistent handling of broken symlinks; writing to a symlink pointing to a non-existent target writes to that target.
  • testSymlinks5ProjectFile. Ensures proper handling of a symlinked project file and its "%_attachments.zip", including cases of broken symlinks.

Disclaimer: While not many users will write to broken symlinks or use symlinked project files, this PR ensures QGIS behaves consistently on Linux systems. These fixes benefit users who rely on symlinks for dynamic data, distributed storage, or large-file workflows like git-annex.

Related PR: A complementary fix in qgspathresolver.cpp is submitted under #60109. Please consider merging them together and backporting to the latest version. These are very simple fixes.

@github-actions github-actions bot added this to the 3.42.0 milestone Jan 14, 2025
@strk
Copy link
Contributor

strk commented Jan 20, 2025

Great to see such care in describing the PR and writing the tests, thank you !

Copy link

github-actions bot commented Jan 20, 2025

🪟 Windows builds

Download Windows builds of this PR for testing.
Debug symbols for this build are available here.
(Built from commit 54d33e6)

🪟 Windows Qt6 builds

Download Windows Qt6 builds of this PR for testing.
(Built from commit 54d33e6)

- Prevent QGIS from silently resolving symlinks in qgspathresolver.cpp
- Respect symlink for “%_attachments.zip” companion file in .qgs project
- Ensure consistent resolution of the project path
- Add new tests to verify good behaviours in common symlink scenarios
- Fix formatting
@vsydorov
Copy link
Author

Previously I've covered cases when project file and layer file were symlinks. Now this handles consistently the final possibility: when project folder is a symlink. Added an appropriate test testSymlinks6ProjectFolder(). Squashed and rebased to latest master.

This passes all the CI workflows on my repo clone, could someone please approve the workflows here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants